﻿Public Class u_Ban
    Private Sub LoadData()
        Dim nv As New BanBUS
        gridcontrol.DataSource = nv.GetBan()
    End Sub

    Private Sub btnThem_Click(sender As Object, e As EventArgs) Handles btnThem.Click
        Dim newBan As New BanDTO
        newBan.MaBan = txtMaBan.Text
        newBan.TinhTrang = txtTinhTrang.Text
        Dim BanBUS As New BanBUS
        BanBUS.AddBan(newBan)
        LoadData()
    End Sub

    Private Sub btnXoa_Click(sender As Object, e As EventArgs) Handles btnXoa.Click
        If GridView.FocusedRowHandle <> GridView.RowCount Then
            Dim delBan As New BanDTO
            delBan.MaBan = GridView.GetRowCellValue(GridView.FocusedRowHandle, "MaBan")
            Dim BanBUS As New BanBUS
            BanBUS.DelBan(delBan)
            LoadData()

        End If
    End Sub

    Private Sub btnCapNhat_Click(sender As Object, e As EventArgs) Handles btnCapNhat.Click
        Dim newBan As New BanDTO
        newBan.MaBan = GridView.GetRowCellValue(GridView.FocusedRowHandle, "MaBan")
        newBan.TinhTrang = txtTinhTrang.Text
        Dim BanBUS As New BanBUS
        BanBUS.UpdateBan(newBan)
        LoadData()
    End Sub

    Private Sub GridView_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles GridView.FocusedRowChanged
        txtMaBan.Text = GridView.GetRowCellValue(GridView.FocusedRowHandle, "MaBan")
        txtTinhTrang.Text = GridView.GetRowCellValue(GridView.FocusedRowHandle, "TinhTrang")
    End Sub

    Private Sub u_Ban_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadData()
    End Sub
End Class